package dbutils;

import org.apache.log4j.Logger;

import java.sql.Connection;
import java.sql.SQLException;

public class TransactionManager {
	
	private static Logger log=Logger.getLogger(TransactionManager.class);

	public void beginTransaction() throws SQLException {
		Connection connection=DBConnection.getConnection();
		connection.setAutoCommit(false);

	}
	
	public void commit(){
		try(Connection connection=DBConnection.getConnection()){
			connection.commit();
			connection.setAutoCommit(true);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void rollback() {
		try(Connection connection=DBConnection.getConnection()){
			connection.rollback();
			connection.setAutoCommit(true);
		} catch (SQLException e) {
			e.printStackTrace();
		}		
	}
	
}
